package com.bsj.travel.monitor.web.controller;

import com.bsj.travel.def.common.DTO.web.otaUpgrade.OtaUpgradeDTO;
import com.bsj.travel.def.common.DTO.web.otaUpgrade.OtaUpgradeSearchDTO;
import com.bsj.travel.def.common.VO.OtaUpgradeVO;
import com.bsj.travel.def.global.JsonResult;
import com.bsj.travel.monitor.service.OtaUpgradeService;
import com.bsj.travel.security.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/***
 * @description OtaUpgradeController
 * @author LiJiaXin
 * @version 1.0.0
 * @time 2024/1/26 16:39
 **/
@RestController
@RequestMapping("/otaUpgrade")
public class OtaUpgradeController {

    @Autowired
    private OtaUpgradeService otaUpgradeService;

    /**
     * 添加OTA升级
     *
     * @param otaUpgradeDTO
     * @return com.bsj.travel.def.global.JsonResult
     * @author ljx
     * @time 2024/1/26 17:35
     */
    @PostMapping("/add")
    @RequiresPermissions(value = "otaUpgrade:operation:add")
    public JsonResult add(@Validated OtaUpgradeDTO otaUpgradeDTO) {
        return otaUpgradeService.addOtaUpgrade(otaUpgradeDTO);
    }

    /**
     * 删除OTA升级
     *
     * @param id
     * @return com.bsj.travel.def.global.JsonResult
     * @author ljx
     * @time 2024/1/26 17:35
     */
    @PostMapping("/delete/{id}")
    @RequiresPermissions(value = "otaUpgrade:operation:delete")
    public JsonResult delete(@PathVariable Long id) {
        return otaUpgradeService.deleteOtaUpgrade(id);
    }

    /**
     * 修改OTA升级
     *
     * @param otaUpgradeDTO
     * @return com.bsj.travel.def.global.JsonResult
     * @author ljx
     * @time 2024/1/26 17:36
     */
    @PostMapping("/update")
    @RequiresPermissions(value = "otaUpgrade:operation:update")
    public JsonResult update(@Validated OtaUpgradeDTO otaUpgradeDTO) {
        return otaUpgradeService.updateOtaUpgrade(otaUpgradeDTO);
    }

    /**
     * 根据id获取OTA升级信息
     *
     * @param id
     * @return com.bsj.travel.def.global.JsonResult<com.bsj.travel.def.common.VO.OtaUpgradeVO>
     * @author ljx
     * @time 2024/1/26 17:36
     */
    @GetMapping("/getById/{id}")
    @RequiresPermissions(value = "otaUpgrade:info:getById")
    public JsonResult<OtaUpgradeVO> getById(@PathVariable("id") Long id) {
        OtaUpgradeVO otaUpgradeVO = otaUpgradeService.getOtaUpgradeInfoById(id);
        return JsonResult.success(otaUpgradeVO);
    }

    /**
     * OTA升级分页
     *
     * @param otaUpgradeSearchDTO
     * @return com.bsj.travel.def.global.JsonResult<java.util.List<com.bsj.travel.def.common.VO.OtaUpgradeVO>>
     * @author ljx
     * @time 2024/1/26 17:37
     */
    @GetMapping("/page")
    @RequiresPermissions(value = "otaUpgrade:info:page")
    public JsonResult<List<OtaUpgradeVO>> page(@Validated OtaUpgradeSearchDTO otaUpgradeSearchDTO) {
        return otaUpgradeService.pageOtaUpgrade(otaUpgradeSearchDTO);
    }

}
